package video.seconddemo;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import protocbuf.protoc.DataInfo;

public class ProtocServerHandler extends SimpleChannelInboundHandler<DataInfo.MyMessage> {

    @Override
    protected void channelRead0(ChannelHandlerContext channelHandlerContext, DataInfo.MyMessage myMessage) throws Exception {
        DataInfo.MyMessage.DataType dataType = myMessage.getDataType();

        if (dataType == DataInfo.MyMessage.DataType.StudentType){
            System.out.println("im student");
            DataInfo.Student student = myMessage.getStudent();
            System.out.println(student.getName());
            System.out.println(student.getAge());
            System.out.println(student.getAddress());
        }else if (dataType == DataInfo.MyMessage.DataType.TeacherType){
            DataInfo.Teacher teacher = myMessage.getTeacher();
            System.out.println("im teacher");
            System.out.println(teacher.getName());
            System.out.println(teacher.getClass_());
            System.out.println(teacher.getAge());
        }
    }
}
